<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="公司名称">
              <j-input placeholder="请输入公司名称" v-model="queryParam.corpname"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="纳税人识别号">
              <j-input placeholder="请输入纳税人识别号" v-model="queryParam.nsrsbh"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="联系人手机">
              <j-input placeholder="请输联系人手机" v-model="queryParam.lxrsj"></j-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="认证状态">
              <j-dict-select-tag placeholder="请选择认证状态" v-model="queryParam.status" dictCode="corpinfo_status"/>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="企业类型">
              <j-dict-select-tag placeholder="请选择企业类型" v-model="queryParam.qylx" dictCode="corpinfo_type"/>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="12" :lg="11" :md="12" :sm="24">
              <a-form-item label="注册时间">
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择开始时间" class="query-group-cust" v-model="queryParam.createTime_begin"></j-date>
                <span class="query-group-split-cust"></span>
                <j-date :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" placeholder="请选择结束时间" class="query-group-cust" v-model="queryParam.createTime_end"></j-date>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <a-modal
      title="合同"
      :visible="visibleHT"
      width="1200px"
      cancelText="关闭"
      @cancel="HzClose"
    >
      <div  id="hz" style="width:1160px;height:475px;overflow-y:auto;">
        <iframe style="width: 100%;height: 100%;" :src="htImgUrl"></iframe>
      </div>

      <template slot="footer">
        <a-button @click="HzClose">关闭</a-button>
      </template>

    </a-modal>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
    </div>

    <div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleEdit(record)" v-if="record.status == 1">设置费率</a>-->
          <!--<a-divider type="vertical" v-if="record.status == 1" />-->
          <a @click="handleEdit(record)" >编辑</a>
          <a-divider type="vertical"  />
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" v-if="record.status == 1 && record.ptzhfwfl >= 0" />
          <a-popconfirm title="确定通过审核吗?" @confirm="() => handleChange(record.id,2)" v-if="record.status == 1 && record.ptzhfwfl >= 0">
            <a>通过</a>
          </a-popconfirm>
          <a-divider type="vertical" v-if="record.status == 1" />
          <a-popconfirm title="确定驳回吗?" @confirm="() =>refuseReason(record)" v-if="record.status == 1">
            <a>驳回</a>
          </a-popconfirm>
  <a-divider type="vertical" v-if="record.status == 2 && record.qylx ==3" />
          <a-popconfirm title="确定要在银行生成子账户吗?" @confirm="() =>todmanbr(record)" v-if="record.status == 2 && record.qylx ==3 && record.dmanbr==null">
            <a>生成子账户</a>
          </a-popconfirm>
            <a @click="showdmanbr(record)" v-if="record.status == 2 && record.qylx ==3 && record.dmanbr!=null">查看子账户</a>
        </span>
      </a-table>

      <a-modal
        title="提示"
        :visible="visibleReason"
        :confirm-loading="false"
        @ok="handleOkReason"
        @cancel="handleCancelReason"
      >
        <a-form-item label="拒绝理由" >
          <a-textarea placeholder="请输入50字以内..." :rows="4" v-model="reason" maxLength="50" />
        </a-form-item>

      </a-modal>
    </div>

    <lhyg-corpinfo-modal ref="modalForm" @ok="modalFormOk"></lhyg-corpinfo-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import LhygCorpinfoModal from './modules/LhygCorpinfoModal'
  import JDictSelectTag from '@/components/dict/JDictSelectTag.vue'
  import JDate from '@/components/jeecg/JDate.vue'
  import JInput from '@/components/jeecg/JInput'
  import { getAction, postAction } from '@api/manage'

  export default {
    name: 'LhygCorpinfoList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      JDictSelectTag,
      JDate,
      LhygCorpinfoModal,
      JInput,
    },
    data () {
      return {
        description: '企业信息表管理页面',
        reason:'', // 拒绝理由
        records:[], // 通过和拒绝的数据
        visibleReason:false, // 拒绝理由控制隐藏显示
        visibleHT:false,
        htImgUrl:'',
        // 表头
        columns: [
          {
            title:'注册时间',
            align:"center",
            dataIndex: 'createTime'
          },
          {
            title:'公司名称',
            align:"center",
            dataIndex: 'corpname'
          },
          {
            title:'纳税人识别号',
            align:"center",
            dataIndex: 'nsrsbh'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'username'
          },
          {
            title:'联系人姓名',
            align:"center",
            dataIndex: 'lxrxm'
          },
          {
            title:'联系人手机',
            align:"center",
            dataIndex: 'lxrsj'
          },

          {
            title:'平台综合服务费费率',
            align:"center",
            dataIndex: 'ptzhfwfl'
          },
          {
            title:'企业类型',
            align:"center",
            dataIndex: 'qylx_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/corpinfo/lhygCorpinfo/list",
          delete: "/corpinfo/lhygCorpinfo/delete",
          deleteBatch: "/corpinfo/lhygCorpinfo/deleteBatch",
          exportXlsUrl: "/corpinfo/lhygCorpinfo/exportXls",
          importExcelUrl: "corpinfo/lhygCorpinfo/importExcel",
          updateStatus: "/corpinfo/lhygCorpinfo/updateStatus",
        },
        dictOptions:{},
      }
    },
    created() {
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      handleOkReason(){
        let that = this;
        let formData=new FormData();
        formData.append('id',that.records.id);
        // formData.append('id','1736564314352406529');
        formData.append('status','0');
        formData.append('reason',that.reason);
        postAction("/corpinfo/lhygCorpinfo/updateStatus",formData).then(res => {
          if(res.code==200){
            that.$message.success(res.message);
            that.searchQuery();
            that.visibleReason = false
          }else{
            that.$message.error(res.message)
          }
        }).catch(err => {
          that.$message.success("审核失败")
        });
      },
      handleCancelReason(){
        this.visibleReason = false
      },
      refuseReason(record){
        let that = this;
        that.records = record;
        that.reason = '';
        that.visibleReason = true
      },
      initDictConfig(){
      },
      htfj(record) {
        let that = this;
        that.htImgUrl = record.htdz;
        that.visibleHT = true;
      },
      HzClose(){
        this.visibleHT = false;
      },
      showdmanbr(record){
        this.$message.success("您的企业名称为：" + record.dmanam + " 您的所属银行子账户为: " + record.dmanbr);
      },
      todmanbr(record){
        let that = this;
        let formData=new FormData();
        formData.append('id',record.id);
        // formData.append('id','1736564314352406529');
        // formData.append('status','0');
        // formData.append('reason',that.reason);
        postAction("/corpinfo/lhygCorpinfo/todmanbr",formData).then(res => {
          if(res.code==200){
            that.$message.success(res.message);
            that.searchQuery();
            that.visibleReason = false
          }else{
            that.$message.error(res.message)
          }
        }).catch(err => {
          that.$message.success("审核失败")
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
